package cn.donting.jme.edit.ui.scenetree.meum;

import cn.donting.jme.edit.ui.scenetree.ClipBoard;
import cn.donting.jme.edit.ui.scenetree.SpatialTreeItem;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import javafx.event.ActionEvent;
import javafx.scene.input.MouseEvent;

public class PasteMenuItem extends AbsTreeMenuItem {
    public PasteMenuItem() {
        super("粘贴");
    }

    @Override
    public boolean isAvailable(ClipBoard clipBoard) {
        if (clipBoard.getSelectSpatial() instanceof Node) {
            return clipBoard.getCopy() != null || clipBoard.getCut() != null;
        }
        return false;
    }


    @Override
    public void action(ClipBoard clipBoard) {
        if (clipBoard.getCopy() != null) {
            Spatial copy = clipBoard.getCopy();
            //生成item
            //TODO: J3eEditSavable 映射关系
            Spatial clone = copy.clone();
            clipBoard.getSceneTreeNodeView().addSpatialToSelectNode(clone);
            clipBoard.setCopy(null);
        }
        if (clipBoard.getCut() != null) {
            SpatialTreeItem cut = clipBoard.getCut();
            clipBoard.getSceneTreeNodeView().moveSelectSpatial(cut);
        }

    }
}
